<template>
<view class="page-e tn-safe-area-inset-bottom" style="height: 100%;overflow-y: scroll;">

  <view class="tn-margin-left tn-margin-right" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
    <!-- 图标logo/头像 -->
    <view :class="{'skeleton': skeleton}" class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin-bottom" @click="tn('/pages/mine/detail/detail')">
      <view class="justify-content-item">
        <view class="tn-flex tn-flex-col-center tn-flex-row-left" v-if="isLogin">
          <view class="logo-pic tn-shadow">
            <view class="logo-image">
              <view class="tn-shadow-blur"
                  :style="{backgroundImage: 'url(' + (vuex_user? `${oss.endpoint}/${oss.bucket}/${vuex_user.avatar}` : '') + ')'}"
                  style="width: 110rpx;height: 110rpx;background-size: cover;overflow: hidden;">
              </view>
            </view>
          </view>
          <view class="tn-padding-right">
            <view class="tn-padding-right tn-padding-left-sm">
              <text class="tn-color-wallpaper tn-text-xl tn-text-bold"> {{ vuex_user.nickname || vuex_user.username }} </text>
            </view>
            <view class="tn-padding-right tn-padding-top-xs tn-padding-left-sm tn-text-ellipsis">
              <text class="tn-color-gray">uid: {{ vuex_user.username }}</text>
            </view>
          </view>
        </view>
      </view>
      <view class="justify-content-item">
          <view class="tn-color-gray tn-icon-right" v-if="isLogin"></view>
      </view>
    </view>

    <!-- #ifndef MP-WEIXIN -->
    <!-- 没有授权，则显示这个授权按钮-->
    <view class="tn-flex tn-flex-row-between" v-if="!isLogin" >
      <view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
        <tn-button @click="tn('/pages/login/login')" shape="round" backgroundColor="#1D2541" fontColor="#ffffff" padding="20rpx 0" width="40%" shadow>
          <text class="">立即登录</text>
        </tn-button>
      </view>
    </view>
    <!-- #endif -->

    <!-- #ifdef MP-WEIXIN -->
    <!-- 没有授权，则显示这个授权按钮-->
    <view class="tn-flex tn-flex-row-between" v-if="!isLogin" >
      <view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
        <tn-button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" shape="round" backgroundColor="#1D2541" fontColor="#ffffff" padding="20rpx 0" width="40%"
          shadow>
          <text class="tn-icon-wechat tn-padding-right-xs tn-text-xl"></text>
          <text class="">授权登录</text>
        </tn-button>
      </view>
    </view>
    <!-- #endif -->
    <view class="tn-margin-top-xl">
      <view class="button-number tn-flex tn-flex-row-between tn-flex-col-center tn-shadow-blur"
        style="background: linear-gradient(-120deg, #3E445A, #31374A, #2B3042, #262B3C);">
        <view class="tn-margin-left">
          <view class="tn-flex tn-flex-col-center" style="color: #F1C68E;margin-top: -20rpx;">
            <text class="tn-text-bold tn-text-xl">权益</text>
            <!-- <text class="tn-icon-vip-text tn-text-center" style="font-size: 92rpx;"></text> -->
          </view>
          <view class='tn-color-white tn-text-sm'>快速开发，助力事业一骑绝尘！</view>
        </view>
        <view class="tn-margin-right">
          <tn-button shape="round" backgroundColor="#F1C68E" fontColor="#634738" padding="10rpx 0"
            width="160rpx" shadow>
            <text class="tn-icon-vip tn-padding-right-sm tn-text-lg"></text>
            <text class="tn-text-bold">VIP</text>
          </tn-button>
        </view>

        <view class="tnwave waveAnimation">
          <view class="waveWrapperInner bgTop">
            <view class="wave waveTop"
              style="background-image: url('https://tnuiimage.tnkjapp.com/wave/wave-2.png')"></view>
          </view>
          <view class="waveWrapperInner bgMiddle">
            <view class="wave waveMiddle"
              style="background-image: url('https://tnuiimage.tnkjapp.com/wave/wave-2.png')"></view>
          </view>
          <view class="waveWrapperInner bgBottom">
            <view class="wave waveBottom"
              style="background-image: url('https://tnuiimage.tnkjapp.com/wave/wave-1.png')"></view>
          </view>
        </view>

      </view>
    </view>

    <!-- #ifdef MP-WEIXIN -->
    <!-- 更多信息-->
    <view class="wallpaper-shadow tn-margin-top-lg tn-padding-top-sm tn-padding-bottom-sm">
      <tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30" @click="navAddress">
        <view class="tn-flex tn-flex-col-center">
          <view class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
            style="color: #7C8191;">
            <view class="tn-icon-message-fill"></view>
          </view>
          <view class="tn-flex tn-flex-row-between" style="width: 100%;">
            <view class="tn-margin-left-sm">收货地址</view>
            <view class="tn-color-gray tn-icon-right"></view>
          </view>
        </view>
      </tn-list-cell>
    </view>
    <!-- #endif -->

    <view class="wallpaper-shadow tn-margin-top-lg tn-margin-bottom-lg tn-padding-top-sm tn-padding-bottom-sm" :class="{'skeleton': skeleton}">
      <!-- #ifdef MP-WEIXIN -->
      <tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30">
        <button class="tn-flex tn-flex-col-center tn-button--clear-style" open-type="contact">
          <view class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
            style="color: #7C8191;">
            <view class="tn-icon-service-fill"></view>
          </view>
          <view class="tn-flex tn-flex-row-between" style="width: 100%;">
            <view class="tn-margin-left-sm">在线客服</view>
            <view class="tn-color-gray tn-icon-right"></view>
          </view>
        </button>
      </tn-list-cell>
      <tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30">
        <button class="tn-flex tn-flex-col-center tn-button--clear-style" open-type="feedback">
          <view class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
            style="color: #7C8191;">
            <view class="tn-icon-message-fill"></view>
          </view>
          <view class="tn-flex tn-flex-row-between" style="width: 100%;">
            <view class="tn-margin-left-sm">问题反馈</view>
            <view class="tn-color-gray tn-icon-right"></view>
          </view>
        </button>
      </tn-list-cell>
      <!-- #endif -->
      <tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30">
        <button class="tn-flex tn-flex-col-center tn-button--clear-style" @click="tn('/pages/mine/about/about')">
          <view class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
                style="color: #7C8191;">
            <view class="tn-icon-tip-fill"></view>
          </view>
          <view class="tn-flex tn-flex-row-between" style="width: 100%;">
            <view class="tn-margin-left-sm">关于我们</view>
            <view class="tn-color-gray tn-icon-right"></view>
          </view>
        </button>
      </tn-list-cell>
      <tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30">
        <button class="tn-flex tn-flex-col-center tn-button--clear-style" @click="tn('/pages/mine/setting/setting')">
          <view class="icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center"
                style="color: #7C8191;">
            <view class="tn-icon-set-fill"></view>
          </view>
          <view class="tn-flex tn-flex-row-between" style="width: 100%;">
            <view class="tn-margin-left-sm">设置</view>
            <view class="tn-color-gray tn-icon-right"></view>
          </view>
        </button>
      </tn-list-cell>
    </view>
  </view>
</view>
</template>

<script>
import { mapState } from 'vuex'
import { obtainPhoneNumber } from "@/api/system/weixin";
import { wxLogin } from "@/api/auth/auth";
import { findInfo } from "@/api/system/self";
import { oss } from '@/config/config.json'

	export default {
		data() {
			return {
        isLogin: false,
        skeleton: false,
        oss
      }
		},
    computed: {
      ...mapState(['vuex_user']),
    },
    onLoad() {
      setTimeout(() => {
        this.skeleton = false
      }, 500)
    },
		onShow() {
      this.isLogin = uni.$t.auth.isLogin()
		},
		methods: {
      tn(url) {
        uni.navigateTo({
          url: url
        })
      },
      // #ifdef MP-WEIXIN
      // 收货地址
      navAddress() {
        uni.chooseAddress({})
      },
      async getPhoneNumber(event) {
        const { code } = event;
        if (code) {
          try {
            uni.showLoading({title: '正在登录'})
            const { data: phone } = await obtainPhoneNumber(code)
            const { code: js_code } = await this.$t.utils.login()
            const { data: token } = await wxLogin({phone: phone?.phoneNumber, js_code})
            uni.$t.auth.setToken(token)
            const { data: self } = await findInfo()
            this.$t.vuex('vuex_user', self)
            this.isLogin = uni.$t.auth.isLogin()
            uni.hideLoading()
          } catch (e) {
            uni.hideLoading()
          }
        }
      },
	    // #endif

			// 复制微信
			copyUid() {
				uni.setClipboardData({
					data: this.vuex_user.username,
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page-e {
		max-height: 100vh;
	}
	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}
	.tn-color-wallpaper {
		color: #1D2541;
	}
	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;
		&__back {
			margin: auto 5rpx;
			font-size: 40rpx;
			margin-right: 10rpx;
			flex-basis: 5%;
			width: 100rpx;
			position: absolute;
		}
	}
	/* 自定义导航栏内容 end */
	/* 顶部背景图 start */
	.top-backgroup {
		height: 450rpx;
		z-index: -1;
		.backgroud-image {
			width: 100%;
			height: 100%;
      z-index: -1;
		}
	}
	/* 顶部背景图 end */
	/* 图标容器5 start */
	.icon5 {
		&__item {
			// width: 30%;
			background-color: $tn-bg-color;
			border-radius: 10rpx;
			padding: 0rpx;
			margin: 0rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;
			&--icon {
				width: 96rpx;
				height: 96rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;
			}
		}
	}
	/* 用户头像 start */
	.logo-image {
		width: 110rpx;
		height: 110rpx;
		position: relative;
		overflow: hidden;
		border-radius: 50%;
	}
	.logo-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border: 8rpx solid rgba(255, 255, 255, 0.05);
		box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
		border-radius: 50%;
		overflow: hidden;
		// background-color: #FFFFFF;
	}
	/* 页面阴影 start*/
	.wallpaper-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}
	/* 页面阴影 end*/
	/* 图标容器15 start */
	.icon15 {
		&__item {
			width: 30%;
			background-color: $tn-bg-color;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;
			&--icon {
				width: 100rpx;
				height: 100rpx;
				font-size: 60rpx;
				border-radius: 50%;
				margin-bottom: 18rpx;
				position: relative;
				z-index: 1;
				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
				}
			}
		}
	}
	/* 图标容器12 start */
	.icon12 {
		&__item {
			width: 30%;
			background-color: $tn-bg-color;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;
			&--icon {
				width: 15rpx;
				height: 15rpx;
				font-size: 50rpx;
				border-radius: 50%;
				margin-bottom: 38rpx;
				position: relative;
				z-index: 1;
				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
				}
			}
		}
	}
	/* 图标容器1 start */
	.icon1 {
		&__item {
			// width: 30%;
			background-color: $tn-bg-color;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;
			&--icon {
				width: 40rpx;
				height: 40rpx;
				font-size: 40rpx;
				border-radius: 50%;
				position: relative;
				z-index: 1;
				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
				}
			}
		}
	}
	/* 图标容器1 end */
	.button-shake {
		animation: shake 4s infinite;
	}
	@keyframes shake {
		5%, 50% {
			transform: scale(1);
		}
		10% {
			transform: scale(0.9);
		}
		15% {
			transform: scale(1.15);
		}
		20% {
			transform: scale(1.15) rotate(-5deg);
		}
		25% {
			transform: scale(1.15) rotate(5deg);
		}
		30% {
			transform: scale(1.15) rotate(-3deg);
		}
		35% {
			transform: scale(1.15) rotate(2deg);
		}
		40% {
			transform: scale(1.15) rotate(0);
		}
	}
	/* 背景波浪高度 */
	.button-number {
		width: 100%;
		height: 150rpx;
		border-radius: 15rpx;
		position: relative;
		z-index: 1;
	}
	/* 动态背景波浪*/
	@keyframes move_wave {
		0% {
			transform: translateX(0) translateZ(0) scaleY(1)
		}
		50% {
			transform: translateX(-25%) translateZ(0) scaleY(1)
		}
		100% {
			transform: translateX(-50%) translateZ(0) scaleY(1)
		}
	}
	.tnwave {
		overflow: hidden;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		top: 0;
		margin: auto;
		z-index: -1;
		border-radius: 15rpx;
	}
	.waveWrapperInner {
		position: absolute;
		width: 100%;
		overflow: hidden;
		height: 100%;
	}
	.wave {
		position: absolute;
		left: 0;
		width: 200%;
		height: 100%;
		background-repeat: repeat no-repeat;
		background-position: 0 bottom;
		transform-origin: center bottom;
	}
	.bgTop {
		opacity: 0.1;
	}
	.waveTop {
		background-size: 50% 45px;
	}
	.waveAnimation .waveTop {
		animation: move_wave 4s linear infinite;
	}
	.bgMiddle {
		opacity: 0.2;
	}
	.waveMiddle {
		background-size: 50% 40px;
	}
	.waveAnimation .waveMiddle {
		animation: move_wave 3.5s linear infinite;
	}
	.bgBottom {
		opacity: 0.3;
	}
	.waveBottom {
		background-size: 50% 35px;
	}
	.waveAnimation .waveBottom {
		animation: move_wave 2s linear infinite;
	}
</style>
